/* =========================================================

文件名称:dataTypeCtrl.js
文件描述:数据类型控件
设计作者:罗向林
编码作者:罗向林
完成日期:2016-08-22

========================================================= */

// 外部调用初始化控件方法
function initDataTypeCtrl(dataType,callBackFunc){
    var htmlVal = initHtml2();
    $("#dataTypeCtrl").html(htmlVal);
	// 选择报表类型时
	/*$("input[name=dTypeTime]").click(function() {
		var selVal = $("input[name=dTypeTime]:checked").val();
		dataType = parseInt(selVal);
		initData(dataType, callBackFunc);
	});*/
	
	initData(dataType, callBackFunc);
}
function initDataTypeCtrl2(dataType,callBackFunc){
    var htmlVal = initHtml2();
    $("#dataTypeCtrl").html(htmlVal);
	
	initData2(dataType, callBackFunc);
}

// 外部调用获取时间方法
function getQueryParam() {
	var queryParams = {};
	queryParams.dataType = dataType;
	queryParams.valid = true;

	var startTime, endTime;
	if (dataType == 2 || dataType == 3 || dataType == 7) {
		startTime = $('#txtStartTime').datebox('getValue');
		endTime = $('#txtEndTime').datebox('getValue');
		var startHour = $('#cmbStartHour').combobox("getValue");
		var endHour = $('#cmbEndHour').combobox("getValue");
		startTime = startTime + " " + startHour + ":00:00";
		endTime = endTime + " " + endHour + ":59:59";

		if (new Date(endTime + " " + endHour + ":00:00") > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
	} else if (dataType == 4) {
		startTime = $('#txtStartDay').datebox('getValue') + " 00:00:00";
		endTime = $('#txtEndDay').datebox('getValue') + " 23:59:59";

		if (new Date(endTime) > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
	} else if (dataType == 5 ) {
		startTime = $('#txtStartMonth').datebox('getValue') + "-01 00:00:00";
		endTime = $('#txtEndMonth').datebox('getValue') +　"-01";
		var endTimeTemp = new Date(endTime);
		var eTime = new Date(new Date(endTimeTemp.getFullYear(), endTimeTemp.getMonth() + 1, 1) - 1000);
		endTime = eTime.format("yyyy-MM-dd hh:mm:ss");

		if (endTimeTemp > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
	}else if(dataType == 6){
		startTime = $('#cmbStartYear').combobox('getValue') + "-01-01 00:00:00";
		endTime = (parseInt($('#cmbEndYear').combobox('getValue')) + 1) +　"-01-01";
		var year = parseInt($('#cmbEndYear').combobox('getValue'));
		var eTime = new Date();
		if (year != eTime.getFullYear()){
			var endTimeTemp = new Date(endTime);
			eTime = new Date(new Date(endTimeTemp.getFullYear(), endTimeTemp.getMonth(), 1) - 1000);
		}

		endTime = eTime.format("yyyy-MM-dd hh:mm:ss");

		if (endTimeTemp > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
	}

	if (new Date(startTime) > new Date(endTime)) {
		$.messager.alert('提示', '<br>起始时间不能大于结束时间！<br>', 'info');
		queryParams.valid = false;
	}

	queryParams.startTime = startTime;
	queryParams.endTime = endTime;

	return queryParams;
}
//外部调用:获取时间方法(均值数据类型)
function getAvgQueryParam() {
	var queryParams = {};
	queryParams.dataType = dataType;
	queryParams.valid = true;

	var startTime, endTime;
	if (dataType == 'avg1' ||dataType == 'avg2' || dataType == 'avg3'|| dataType == 'avg7') {
		startTime = $('#txtStartTime').datebox('getValue');
		endTime = $('#txtEndTime').datebox('getValue');
		var startHour = $('#cmbStartHour').combobox("getValue");
		var endHour = $('#cmbEndHour').combobox("getValue");
		startTime = startTime + " " + startHour + ":00:00";

		var d=new Date(Date.parse(endTime.replace(/-/g,"/")+ " " + endHour + ":00:00"));
		var curDate=new Date();
		if (d > curDate) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
		if (d.toDateString() === curDate.toDateString() && endHour === curDate.getHours().toString()) {
			endTime = endTime + " " + endHour + ":"+curDate.getMinutes()+":"+curDate.getSeconds();
		}else{
			endTime = endTime + " " + endHour + ":59:59";
		}
		
		if (dataType == 'avg2') {
			if (((new Date(endTime)).getTime() - (new Date(startTime)).getTime())> 1000*60*60*24*3) {
				$.messager.alert('提示', '<br>查询时间不能超过3天！<br>', 'info');
				queryParams.valid = false;
			}
		}else {
			if (((new Date(endTime)).getTime() - (new Date(startTime)).getTime())> 1000*60*60*24*30) {
				$.messager.alert('提示', '<br>查询时间不能超过30天！<br>', 'info');
				queryParams.valid = false;
			}
		}
	} else if (dataType == 'avg4') {
		startTime = $('#txtStartDay').datebox('getValue') + " 00:00:00";
		endTime = $('#txtEndDay').datebox('getValue') + " 23:59:59";

		if (new Date(endTime) > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}

		if (((new Date(endTime)).getTime() - (new Date(startTime)).getTime())> 1000*60*60*24*365*2) {
			$.messager.alert('提示', '<br>查询时间不能超过2年！<br>', 'info');
			queryParams.valid = false;
		}
		
	} else if (dataType == 'avg5' ) {
		startTime = $('#txtStartMonth').datebox('getValue') + "-01 00:00:00";
		endTime = $('#txtEndMonth').datebox('getValue') +　"-01";
		var endTimeTemp = new Date(endTime.replace(/-/g,"/"));
		var eTime = new Date(new Date(endTimeTemp.getFullYear(), endTimeTemp.getMonth() + 1, 1) - 1000);
		endTime = eTime.format("yyyy-MM-dd hh:mm:ss");

		if (endTimeTemp > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
	}else if(dataType == 'avg6'){
		startTime = $('#cmbStartYear').combobox('getValue') + "-01-01 00:00:00";
		endTime = (parseInt($('#cmbEndYear').combobox('getValue')) + 1) +　"-01-01";
		var year = parseInt($('#cmbEndYear').combobox('getValue'));
		var eTime = new Date();
		if (year != eTime.getFullYear()){
			var endTimeTemp = new Date(endTime.replace(/-/g,"/"));
			eTime = new Date(new Date(endTimeTemp.getFullYear(), endTimeTemp.getMonth(), 1) - 1000);
		}

		endTime = eTime.format("yyyy-MM-dd hh:mm:ss");

		if (endTimeTemp > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
	}

	if (new Date(startTime) > new Date(endTime)) {
		$.messager.alert('提示', '<br>起始时间不能大于结束时间！<br>', 'info');
		queryParams.valid = false;
	}

	queryParams.startTime = startTime;
	queryParams.endTime = endTime;

	return queryParams;
}
//外部调用获取时间方法
/**
 * initHourCtrl(dataType,num)专用
 * */
function getHourQueryParam2() {
	var queryParams = {};
	queryParams.dataType = dataType;
	queryParams.valid = true;

	var startTime, endTime;
	var curDate=new Date();
	var hour=curDate.getHours();
	var minute=curDate.getMinutes();
	var second=curDate.getSeconds();
	hour=hour<10?("0"+hour):hour;
	minute=minute<10?("0"+minute):minute;
	second=second<10?("0"+second):second; 
	if (dataType == 2 || dataType == 3 || dataType == 1) {
		startTime = $('#txtStartTime').datebox('getValue');
		endTime = $('#txtEndTime').datebox('getValue');
		var startHour = $('#cmbStartHour').combobox("getValue");
		var endHour = $('#cmbEndHour').combobox("getValue");
		startTime = startTime + " " + startHour + ":00:00";
		
		var d=new Date(Date.parse(endTime.replace(/-/g,"/")+ " " + endHour + ":00:00"));
		if (d > curDate) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
		if (d.toDateString() === curDate.toDateString() && endHour === curDate.getHours().toString()) {			
			endTime = endTime + " " + endHour + ":"+minute+":"+second;
		}else{
			endTime = endTime + " " + endHour + ":59:59";
		}
	} else if (dataType == 4) {
		startTime = $('#txtStartDay').datebox('getValue') + " 00:00:00";
		endTime = $('#txtEndDay').datebox('getValue');

		var d=new Date(Date.parse(endTime.replace(/-/g,"/")));
		if(d >curDate){
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}
		if (d.toDateString() === curDate.toDateString()) {		
			endTime=endTime +" "+ hour +":"+minute+":"+second;
		}else{
			endTime=endTime +" 23:59:59";
		}
	} 

	if (new Date(Date.parse(startTime.replace(/-/g,"/"))) > new Date(Date.parse(endTime.replace(/-/g,"/")))) {
		$.messager.alert('提示', '<br>起始时间不能大于结束时间！<br>', 'info');
		queryParams.valid = false;
	}

	queryParams.startTime = startTime;
	queryParams.endTime = endTime;

	return queryParams;
}
// 外部调用初始化控件方法（小时）
function initHourCtrl(){
    var htmlDataHour = initHourHtml();
    $("#dataTypeCtrl").html(htmlDataHour);
	
	initDataHour();
}
//外部调用初始化控件方法（小时）
function initHourCtrl(dataType,num){
    var htmlDataHour = initHourHtml();
    $("#dataTypeCtrl").html(htmlDataHour);
	
	initDataHour(dataType,num);
}
// 外部调用获取时间方法（小时）
function getHourQueryParam() {
	var queryParams = {};
	queryParams.valid = true;

	var startTime, endTime;
		startTime = $('#txtStartTime').datebox('getValue');
		endTime = $('#txtEndTime').datebox('getValue');
		var startHour = $('#cmbStartHour').combobox("getValue");
		var endHour = $('#cmbEndHour').combobox("getValue");
		startTime = startTime + " " + startHour + ":00:00";
		endTime = endTime + " " + endHour + ":59:59";

		if (new Date(Date.parse(endTime.replace(/-/g,"/") + " " + endHour + ":00:00")) > new Date()) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}

	if (new Date(startTime) > new Date(endTime)) {
		$.messager.alert('提示', '<br>起始时间不能大于结束时间！<br>', 'info');
		queryParams.valid = false;
	}

	queryParams.startTime = startTime;
	queryParams.endTime = endTime;

	return queryParams;
}

function initHtml() {	
	var htmlVal = '<strong><span>数据类型：</span></strong>'; 
	htmlVal += '<input name="dTypeTime" type="radio" value="6" class="margf4" /> 年 ';
	htmlVal += '<input name="dTypeTime" type="radio" value="5" class="margf4" /> 月 ';
	htmlVal += '<input name="dTypeTime" type="radio" value="4" class="margf4 marlf10" /> 日 ';
	htmlVal += '<input name="dTypeTime" type="radio" value="3" class="margf4 marlf10" checked /> 小时 ';
	htmlVal += '<input name="dTypeTime" type="radio" value="7" class="margf4 marlf10" /> 原始 ';
	htmlVal += '<strong><span class="marlf20">选择时间：</span></strong> ';
	htmlVal += '<span id="hour"> ';
	htmlVal += '<input id="txtStartTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
	htmlVal += '<span style="margin-left: 8px;"></span>';
	htmlVal += '<select id="cmbStartHour" class="easyui-combobox" style="width: 80px;"></select> ';
	htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong>';
	htmlVal += '<input id="txtEndTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" /> ';
	htmlVal += '<select id="cmbEndHour" class="easyui-combobox" style="width: 80px;"></select>';
	htmlVal += '</span> ';
	htmlVal += '<span id="day" style="display: none;"> ';
    htmlVal += '<input	id="txtStartDay" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
	htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong> ';
    htmlVal += '<input id="txtEndDay" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
    htmlVal += '</span> ';
    htmlVal += '<span id="month" style="display: none;"> ';
    htmlVal += '<input id="txtStartMonth" class="easyui-datebox" style="width: 120px;" />';
    htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong> ';
    htmlVal += '<input id="txtEndMonth" class="easyui-datebox" style="width: 120px;" />';
    htmlVal += '</span>';
    htmlVal += '<span id="year" style="display: none;"> ';
    htmlVal += '<select id="cmbStartYear" name="cmbStartYear" style="width: 120px;"></select>';
    htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong>';
    htmlVal += '<select id="cmbEndYear" name="cmbEndYear" style="width: 120px;"></select>';
    htmlVal += '</span>';
    
    return htmlVal;
}

function initHtml2() {	
	var htmlVal = '<strong><span>选择时间：</span></strong> ';
	htmlVal += '<span id="hour"> ';
	htmlVal += '<input id="txtStartTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
	htmlVal += '<span style="margin-left: 8px;"></span>';
	htmlVal += '<select id="cmbStartHour" class="easyui-combobox" style="width: 80px;"></select> ';
	htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong>';
	htmlVal += '<input id="txtEndTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" /> ';
	htmlVal += '<select id="cmbEndHour" class="easyui-combobox" style="width: 80px;"></select>';
	htmlVal += '</span> ';
	htmlVal += '<span id="day" style="display: none;"> ';
    htmlVal += '<input	id="txtStartDay" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
	htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong> ';
    htmlVal += '<input id="txtEndDay" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
    htmlVal += '</span> ';
    htmlVal += '<span id="month" style="display: none;"> ';
    htmlVal += '<input id="txtStartMonth" class="easyui-datebox" style="width: 120px;" />';
    htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong> ';
    htmlVal += '<input id="txtEndMonth" class="easyui-datebox" style="width: 120px;" />';
    htmlVal += '</span>';
    htmlVal += '<span id="year" style="display: none;"> ';
    htmlVal += '<select id="cmbStartYear" name="cmbStartYear" style="width: 120px;"></select>';
    htmlVal += '<strong><span style="margin: 0px 8px;">到</span></strong>';
    htmlVal += '<select id="cmbEndYear" name="cmbEndYear" style="width: 120px;"></select>';
    htmlVal += '</span>';
    
    return htmlVal;
}

function initData(type, callBackFunc) {	
	var currData = new Date();
	if (type == 1 || type == 2 || type == 3 || type == 7) {
		$("#hour").show();
		$("#day").hide();
		$("#month").hide();
		$("#year").hide();

		var startHour = [];
		var endHour = [];
		var currHour = currData.getHours();
		var i, item = {};
		for (i = 0; i < 24; i++) {
			item = {
				id : i,
				text : i + "时"
			};
			startHour.push(item);
			endHour.push(item);
		}

		$('#cmbStartHour').combobox({
			data : startHour,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', 0);
			}
		});

		$('#cmbEndHour').combobox({
			data : endHour,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', currHour);
			}
		});

		var curDay = currData.format("yyyy-MM-dd");
		$("#txtStartTime").datebox({});
		$("#txtEndTime").datebox({});
		$("#txtStartTime").datebox("setValue", curDay);
		$("#txtEndTime").datebox("setValue", curDay);		
	} else if (type == 4) {
		$("#hour").hide();
		$("#day").show();
		$("#month").hide();
		$("#year").hide();

		var startDay = (new Date(currData - 7 * 24 * 60 * 60 * 1000))
				.format("yyyy-MM-dd");
		var endDay = (new Date(currData - 24 * 60 * 60 * 1000))
				.format("yyyy-MM-dd");
		$("#txtStartDay").datebox({});
		$("#txtEndDay").datebox({});
		$("#txtStartDay").datebox("setValue", startDay);
		$("#txtEndDay").datebox("setValue", endDay);
	} else if (type == 5) {
		$("#hour").hide();
		$("#day").hide();
		$("#month").show();
		$("#year").hide();

		setDelfaultSelMonth("txtStartMonth");
		setDelfaultSelMonth("txtEndMonth");

		var curMon = new Date().format("yyyy-MM");
		$("#txtStartMonth").datebox("setValue", currData.getFullYear() + "-02");
		$("#txtEndMonth").datebox("setValue", curMon);
	}else if( type == 6){
		$("#hour").hide();
		$("#day").hide();
		$("#month").hide();
		$("#year").show();

		var startTime = [];
		var endTime = [];
		for(var i = 0; i < 5;i++){
			var year = currData.getFullYear() - i;
			startTime.push({id : year, text : year + "年" });
			endTime.push({id : year, text : year + "年" });
		}
		
		$('#cmbStartYear').combobox({
			data : startTime,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', currData.getFullYear());
			}
		});
		
		$('#cmbEndYear').combobox({
			data : endTime,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', currData.getFullYear());
			}
		});
	}
	
	var dataSource = [];
	if (type == 1 || type == 2 || type == 3 || type == 7) {
		if (type == 1 || type == 3 || type == 7) {
			dataSource = [ {
				id : 0,
				text : "未审核数据"
			}, {
				id : 1,
				text : "审核数据"
			} ];
		} else {
			dataSource = [ {
				id : 0,
				text : "未审核数据"
			} ];
		}
	}else{
		dataSource = [ {
			id : 1,
			text : "审核数据"
		} ];
	}
	var defVal = 1; 
	if (type == 1 || type == 2 || type == 3 || type == 7) {
		defVal = 0;		
	}
	systemType=getUrlParam("systemType");
	if(systemType=="104"){
		if(type == 3){
			dataSource = [ {
				id : 1,
				text : "审核数据"
			} ];
			defVal=1;
		}else if(type == 2){
			dataSource = [ {
				id : 0,
				text : "未审核数据"
			}, {
				id : 1,
				text : "审核数据"
			} ];
			defVal=0;
		}
	}
	
	if (callBackFunc != undefined && callBackFunc != null){
		callBackFunc(type, dataSource,defVal);
	}
}
function initData2(type, callBackFunc) {	
	var currData = new Date();
	if (type == 'avg1' || type == 'avg2' || type == 'avg3'|| type == 'avg7') {
		$("#hour").show();
		$("#day").hide();
		$("#month").hide();
		$("#year").hide();

		var startHour = [];
		var endHour = [];
		var currHour = currData.getHours();
		var i, item = {};
		for (i = 0; i < 24; i++) {
			item = {
				id : i,
				text : i + "时"
			};
			startHour.push(item);
			endHour.push(item);
		}

		$('#cmbStartHour').combobox({
			data : startHour,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', (type == 'avg7')?currHour:0);
			}
		});

		$('#cmbEndHour').combobox({
			data : endHour,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', currHour);
			}
		});

		var curDay = currData.format("yyyy-MM-dd");
		$("#txtStartTime").datebox({});
		$("#txtEndTime").datebox({});
		$("#txtStartTime").datebox("setValue", curDay);
		$("#txtEndTime").datebox("setValue", curDay);		
	} else if (type == 'avg4') {
		$("#hour").hide();
		$("#day").show();
		$("#month").hide();
		$("#year").hide();

		var startDay = (new Date(currData - 7 * 24 * 60 * 60 * 1000))
				.format("yyyy-MM-dd");
		var endDay = (new Date(currData - 24 * 60 * 60 * 1000))
				.format("yyyy-MM-dd");
		$("#txtStartDay").datebox({});
		$("#txtEndDay").datebox({});
		$("#txtStartDay").datebox("setValue", startDay);
		$("#txtEndDay").datebox("setValue", endDay);
	} else if (type == 'avg5') {
		$("#hour").hide();
		$("#day").hide();
		$("#month").show();
		$("#year").hide();

		setDelfaultSelMonth("txtStartMonth");
		setDelfaultSelMonth("txtEndMonth");

		var curMon = new Date().format("yyyy-MM");
		$("#txtStartMonth").datebox("setValue", currData.getFullYear() + "-02");
		if(currData.getMonth() === 0){
			$("#txtEndMonth").datebox("setValue", currData.getFullYear() + "-02");
		}else{
			$("#txtEndMonth").datebox("setValue", curMon);
		}
	}else if( type == 'avg6'){
		$("#hour").hide();
		$("#day").hide();
		$("#month").hide();
		$("#year").show();

		var startTime = [];
		var endTime = [];
		for(var i = 0; i < 5;i++){
			var year = currData.getFullYear() - i;
			startTime.push({id : year, text : year + "年" });
			endTime.push({id : year, text : year + "年" });
		}
		
		$('#cmbStartYear').combobox({
			data : startTime,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', currData.getFullYear());
			}
		});
		
		$('#cmbEndYear').combobox({
			data : endTime,
			valueField : 'id',
			textField : 'text',
			onLoadSuccess : function() {
				$(this).combobox('setValue', currData.getFullYear());
			}
		});
	}
	
	var dataSource = [];
	if (type == 'avg2' || type == 'avg3' || type == 'avg7') {
		if (type == 'avg3' || type == 'avg7') {
			dataSource = [ {
				id : 0,
				text : "未审核数据"
			}, {
				id : 1,
				text : "审核数据"
			} ];
		} else {
			dataSource = [ {
				id : 0,
				text : "未审核数据"
			} ];
		}
	}else{
		dataSource = [ {
			id : 1,
			text : "审核数据"
		} ];
	}
	var defVal = 1; 
	if (type === 'avg2' || type === 'avg3' || type === 'avg7') {
		defVal = 0;		
	}
	systemType=getUrlParam("systemType");
	if(systemType=="104"){
		if(type == 'avg3'){
			dataSource = [ {
				id : 1,
				text : "审核数据"
			} ];
			defVal = 1;
		}else if(type == 'avg2'){
			dataSource = [ {
				id : 0,
				text : "未审核数据"
			}, {
				id : 1,
				text : "审核数据"
			} ];
			defVal = 0;
		}
	}
	if (callBackFunc != undefined && callBackFunc != null){
		callBackFunc(type, dataSource,defVal);
	}
}
function initHourHtml() {
    var htmlVal = '<span id="hour"> ';
    htmlVal += '<label class="marlf10">开始时间：</label> ';
    htmlVal += '<input	id="txtStartTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
    htmlVal += '<span style="margin-left: 8px;"></span>';
    htmlVal += '<select id="cmbStartHour" class="easyui-combobox" style="width: 80px;"></select> ';
    htmlVal += '<label class="marlf20" style="margin: 0px 0px 0px 8px;">结束时间：</label>';
    htmlVal += '<input id="txtEndTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" /> ';
    htmlVal += '<select id="cmbEndHour" class="easyui-combobox" style="width: 80px;"></select>';
    htmlVal += '</span> ';

    return htmlVal;
}

function initDataHour() {
    var currData = new Date();

    var startHour = [];
    var endHour = [];
    var currHour = currData.getHours();
    var i, item = {};
    for (i = 0; i < 24; i++) {
        item = {
            id: i,
            text: i + "时"
        };
        startHour.push(item);
        endHour.push(item);
    }

    $('#cmbStartHour').combobox({
        data: startHour,
        valueField: 'id',
        textField: 'text',
        onLoadSuccess: function () {
            $(this).combobox('setValue', 0);
        }
    });

    $('#cmbEndHour').combobox({
        data: endHour,
        valueField: 'id',
        textField: 'text',
        onLoadSuccess: function () {
            $(this).combobox('setValue', currHour);
        }
    });

    var curDay = currData.format("yyyy-MM-dd");
    $("#txtStartTime").datebox({});
    $("#txtEndTime").datebox({});
    $("#txtStartTime").datebox("setValue", curDay);
    $("#txtEndTime").datebox("setValue", curDay);
}
function initDataHour(dataType,num) {
    var currData = new Date();

    var startHour = [];
    var endHour = [];
    var currHour = currData.getHours();
    var i, item = {};
    for (i = 0; i < 24; i++) {
        item = {
            id: i,
            text: i + "时"
        };
        startHour.push(item);
        endHour.push(item);
    }

    $('#cmbStartHour').combobox({
        data: startHour,
        valueField: 'id',
        textField: 'text',
        onLoadSuccess: function () {
        	if (dataType=='1') {
            $(this).combobox('setValue',currHour);
			}else if(dataType=='2'){
				 $(this).combobox('setValue',num==null?currHour:(currHour-num));
			}else{
	        $(this).combobox('setValue', 0);
			}
        }
    });

    $('#cmbEndHour').combobox({
        data: endHour,
        valueField: 'id',
        textField: 'text',
        onLoadSuccess: function () {
            $(this).combobox('setValue', currHour);
        }
    });

    var curDay = currData.format("yyyy-MM-dd");
    var strDay =(new Date(currData-1000*60*60*24)).format("yyyy-MM-dd")
    $("#txtStartTime").datebox({});
    $("#txtEndTime").datebox({});
    $("#txtStartTime").datebox("setValue", dataType=='4'?strDay:curDay);
    $("#txtEndTime").datebox("setValue", curDay);
}

function setDelfaultSelMonth(dateTimeCtrlId) {
	$('#' + dateTimeCtrlId).datebox({
		onShowPanel : function() {// 显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
			span.trigger('click'); // 触发click事件弹出月份层
			if (!tds)
				setTimeout(function() {// 延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
					tds = p.find('div.calendar-menu-month-inner td');
					tds.click(function(e) {
						e.stopPropagation(); // 禁止冒泡执行easyui给月份绑定的事件
						var year = /\d{4}/.exec(span.html())[0]// 得到年份
						, month = parseInt($(this).attr('abbr'), 10) + 1; // 月份
						$('#'+dateTimeCtrlId).datebox('hidePanel')// 隐藏日期对象
						.datebox('setValue', year + '-' + month); // 设置日期的值
					});
				}, 0);
		},
		parser : function(s) {// 配置parser，返回选择的日期
			if (!s)
				return new Date();
			var arr = s.split('-');
			return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
		},
		formatter : function(d) {
			var month = d.getMonth();
			if (month < 10) {
				month = "0" + month;
			}
			if (d.getMonth() == 0) {
				return d.getFullYear() - 1 + '-' + 12;
			} else {
				return d.getFullYear() + '-' + month;
			}
		}// 配置formatter，只返回年月
	});

	var p = $('#' + dateTimeCtrlId).datebox('panel'), // 日期选择对象
	tds = false, // 日期选择对象中月份
	span = p.find('span.calendar-text'); // 显示月份层的触发控件
}

//外部调用初始化控件方法（只显示到天）
function initDayCtrl(day){
    var htmlDataDay = initDayHtml();
    $("#dataTypeCtrl").html(htmlDataDay);
	
    initDataDay(day);
}
//外部调用初始化控件方法（只显示到天）
function initDayCtrl(dataType,movedUp){
    var htmlDataDay = initDayHtml();
    $("#dataTypeCtrl").html(htmlDataDay);
	
    initDataDay(dataType,movedUp);
}
function initDayHtml() {
    var htmlVal = '<span id="day"> ';
    htmlVal += '<label class="marlf10">开始时间：</label> ';
    htmlVal += '<input	id="txtStartTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" />';
    htmlVal += '<span style="margin-left: 8px;"></span>';
    htmlVal += '<label class="marlf20" style="margin: 0px 0px 0px 8px;">结束时间：</label>';
    htmlVal += '<input id="txtEndTime" class="easyui-datebox" style="width: 120px;" data-options="formatter:dateFormatter,parser:dateParser,validType:\'verifyLegality\'" /> ';
    htmlVal += '</span> ';

    return htmlVal;
}

//function initDataDay(day) {
//    var currData = new Date();
//    var stTime = new Date(currData.getTime() - day*24*60*60*1000);
//    var curDay = currData.format("yyyy-MM-dd");
//    $("#txtStartTime").datebox({});
//    $("#txtEndTime").datebox({});
//    $("#txtStartTime").datebox("setValue", stTime.format("yyyy-MM-dd"));
//     $("#txtEndTime").datebox("setValue", curDay);
//}
/**
 * @dataType 数据类型 1:实时数据;2:分钟数据;3:小时数据;4:日数据;
 * @movedUp 提前多久，单位根据数据类型决定
 * */
function initDataDay(dataType,movedUp) {
	var fomarter='yyyy-MM-dd hh:mm:ss';
	var pre=0;
	switch (dataType) {
	case '1':
		fomarter='yyyy-MM-dd hh:mm:ss';
		pre=1000*movedUp;
		break;
	case '2':
		fomarter='yyyy-MM-dd hh:mm';
		pre=1000*60*movedUp;
		break;
	case '3':
		fomarter='yyyy-MM-dd hh';
		pre=1000*60*60*movedUp;
		break;
	case '4':
		fomarter='yyyy-MM-dd';
		pre=1000*60*60*24*movedUp;
		break;

	default:
		break;
	}
    var currData = new Date();
    var stTime = new Date(currData.getTime() - pre);
    var curDay = currData.format(fomarter);
    $("#txtStartTime").datebox({});
    $("#txtEndTime").datebox({});
    $("#txtStartTime").datebox("setValue", stTime.format(fomarter));
    $("#txtEndTime").datebox("setValue", curDay);
}
// 外部调用获取时间方法（天）
function getDayQueryParam() {
	var queryParams = {};
	queryParams.valid = true;

	var startTime, endTime;
		startTime = $('#txtStartTime').datebox('getValue');
		endTime = $('#txtEndTime').datebox('getValue');
		
		var curDate = new Date();
		 var curHour = curDate.getHours(); 
		 var curMinutes=curDate.getMinutes();
		var curSeconds = curDate.getSeconds()
		 
		startTime = startTime  + " 00:00:00";
		var selEndTime=new Date(endTime + " " + curHour +":"+ curMinutes+":"+curSeconds);
		if (new Date(endTime +" 00:00:00") < new Date(curDate.getFullYear()+"-"+(curDate.getMonth()+1)+"-"+curDate.getDate() +" 00:00:00") ) {
			endTime = endTime + " 23:59:59";
			selEndTime=new Date(endTime);
		}else{
			endTime = endTime + " " + curHour +":"+ curMinutes+":"+curSeconds;
		}
		if (selEndTime > curDate) {
			$.messager.alert('提示', '<br>结束时间不能大于当前时间！<br>', 'info');
			queryParams.valid = false;
		}

	if (new Date(startTime) > new Date(endTime)) {
		$.messager.alert('提示', '<br>起始时间不能大于结束时间！<br>', 'info');
		queryParams.valid = false;
	}

	queryParams.startTime = startTime;
	queryParams.endTime = endTime;

	return queryParams;
}

